package com.taomu.app.zongchouhuli.moudle.mine.contract.impl;

import android.util.Log;

import com.taomu.app.zongchouhuli.entity.BaseChangeResponse;
import com.taomu.app.zongchouhuli.http.api.HttpObserver;
import com.taomu.app.zongchouhuli.http.api.Request;
import com.taomu.app.zongchouhuli.http.res.ResBankEntity;
import com.taomu.app.zongchouhuli.http.res.ResMyBankListEntity;
import com.taomu.app.zongchouhuli.http.res.ResProductEntity;
import com.taomu.app.zongchouhuli.moudle.mine.contract.UserAccountContract;
import com.taomu.app.zongchouhuli.utils.StorageHelper;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;

public class UserAccountPresenter implements UserAccountContract.Presenter {

    private UserAccountContract.View mContractView;

    private CompositeDisposable disposable;

    public UserAccountPresenter(UserAccountContract.View mContractView){
        this.mContractView = mContractView;
        this.disposable = new CompositeDisposable();
    }

    @Override
    public void getBankList(int ship,int take) {
        Request.getIntence().getBankList(StorageHelper.getToken(),String.valueOf(ship),String.valueOf(take))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new HttpObserver<ResMyBankListEntity>(mContractView,disposable,true) {
                    @Override
                    public void onNext(ResMyBankListEntity resProductEntities) {
                        if(mContractView != null){
                            mContractView.setBankList(resProductEntities);
                        }
                    }
                });
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDetch() {
        mContractView = null;
        if(disposable != null){
            disposable.dispose();
            disposable = null;
        }
    }
}
